package processor;

import models.Addr;
import models.Addr.Ownership;
import models.Addr.YearsLived;
import prefix.util.JPAUtil;
import service.exception.ActorException;
import service.exception.ActorException.CODE;
import service.impl.AddrServiceImpl;

public class AddrProcessor extends AddrServiceImpl {

    public AddrProcessor(Addr addr) {
        super(addr);
    }

    public AddrProcessor() {

    }

    public void submitContractInfo(Integer aid, Integer empId, String streetAddress, String city, String province,
            String landPhone, YearsLived yearsLived, Ownership ownerShip, String landPhoneExt) throws ActorException {
        try {
            JPAUtil.beginTransaction();
            this.dbaddr.setValues(aid, empId, streetAddress, city, province, landPhone, yearsLived, ownerShip,
                    landPhoneExt);
            if (this.dbaddr.getId() != null)
                JPAUtil.em().merge(this.dbaddr);
            else
                JPAUtil.em().persist(this.dbaddr);
            JPAUtil.commitTransaction();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new ActorException(CODE.UNKNOWN, e);
        } finally {
            JPAUtil.closeEM();
        }
    }

}
